package com.ruoyi.bearing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bearing.domain.ComponentConditions;
import com.ruoyi.bearing.service.IComponentConditionsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 元器件工况管理Controller
 * 
 * @author lyz
 * @date 2025-03-31
 */
@RestController
@RequestMapping("/bearing/conditions")
public class ComponentConditionsController extends BaseController
{
    @Autowired
    private IComponentConditionsService componentConditionsService;

    /**
     * 查询元器件工况管理列表
     */
    @PreAuthorize("@ss.hasPermi('bearing:conditions:list')")
    @GetMapping("/list")
    public TableDataInfo list(ComponentConditions componentConditions)
    {
        startPage();
        List<ComponentConditions> list = componentConditionsService.selectComponentConditionsList(componentConditions);
        return getDataTable(list);
    }

    /**
     * 导出元器件工况管理列表
     */
    @PreAuthorize("@ss.hasPermi('bearing:conditions:export')")
    @Log(title = "元器件工况管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ComponentConditions componentConditions)
    {
        List<ComponentConditions> list = componentConditionsService.selectComponentConditionsList(componentConditions);
        ExcelUtil<ComponentConditions> util = new ExcelUtil<ComponentConditions>(ComponentConditions.class);
        util.exportExcel(response, list, "元器件工况管理数据");
    }

    /**
     * 获取元器件工况管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('bearing:conditions:query')")
    @GetMapping(value = "/{conditionId}")
    public AjaxResult getInfo(@PathVariable("conditionId") Long conditionId)
    {
        return success(componentConditionsService.selectComponentConditionsByConditionId(conditionId));
    }

    /**
     * 新增元器件工况管理
     */
    @PreAuthorize("@ss.hasPermi('bearing:conditions:add')")
    @Log(title = "元器件工况管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ComponentConditions componentConditions)
    {
        return toAjax(componentConditionsService.insertComponentConditions(componentConditions));
    }

    /**
     * 修改元器件工况管理
     */
    @PreAuthorize("@ss.hasPermi('bearing:conditions:edit')")
    @Log(title = "元器件工况管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ComponentConditions componentConditions)
    {
        return toAjax(componentConditionsService.updateComponentConditions(componentConditions));
    }

    /**
     * 删除元器件工况管理
     */
    @PreAuthorize("@ss.hasPermi('bearing:conditions:remove')")
    @Log(title = "元器件工况管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{conditionIds}")
    public AjaxResult remove(@PathVariable Long[] conditionIds)
    {
        return toAjax(componentConditionsService.deleteComponentConditionsByConditionIds(conditionIds));
    }
}
